package scr
{
	/**
	 * ...
	 * @author a.orleansky
	 */
	import cell.KeyBoard;
	import cell.KeyPad;
	import flash.events.Event;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import img.ChekPlane;
	import img.ScalePlane;
	import ru.gosoplata.model.TmpModel;
	import ru.gosoplata.view.FooterView;
	import uicontrols.ButtonBase;
	import uicontrols.ButtonProvider;
	
	public class ScreenEnterUserData extends ScreenBase implements IScreen
	{
		public var keypad:KeyPad;
		public var keyboard:KeyBoard;
		private var inputtxt0:TextField;
		private var inputtxt1:TextField;
		private var inputtxt2:TextField;
		private var phone_nums_limit:Number = 13;
		
		public var btn_next:ButtonBase;
		private var pic_count:Number=0;
		private var small_format:TextFormat = new TextFormat();
		
		private var pics_info:Array = new Array(new Array("plane_input_chek_surname", TmpModel.IMG_FOLDER + "/input_lic_schet/images/input_isc_plane.png"), 
			new Array("input_keyb_surname", TmpModel.IMG_FOLDER + "/input_lic_schet/images/input_isc_input.png"), 
			new Array("plane_logo", TmpModel.IMG_FOLDER + "/podtvezdenie_nomera/images/plane_logo.png"), 
			new Array("plane_input_phone", TmpModel.IMG_FOLDER + "/input_tel/images/input_tel_sng_plane_32.png"),
			new Array("input_keyb_chek_surname", TmpModel.IMG_FOLDER + "/input_lic_schet/images/input_isc_input_chek.png"));
		
		private var up_txt_str:String = "Введите номер телефона";
		private var down_txt_str:String = "";
		private var txt1_str:String = "";
		private var up_txt:TextField;
		private var down_txt:TextField;
		private var txt1:TextField;
		
		public var testplane:ScalePlane;
		public var addplane1:ScalePlane;
		public var addplane2:ScalePlane;
		public var addplane3:ScalePlane;
		public var addplane4:ScalePlane;
		public var addplane5:ScalePlane;
		public var addplane6:ScalePlane;
		public var addplane7:ScalePlane;
		public var addplane8:ScalePlane;
		public var addplane9:ScalePlane;
		private var addplanecount:Number = 9;
		
		public var chekplane:ChekPlane;
		public var prv_logo:ButtonProvider;
		private var acc_number_length:Number = 4;
		private var acc_number_min_length:Number;
		private var btn_nic_d:ButtonBase;
		private var btn_nic_r:ButtonBase;
		
		private var fields_count:Number = 1;
		public var fields:Array = new Array();
		private var current_indx:Number = 1;
		
		public var txt_type:TextFormat = new TextFormat();
		public var txt_type2:TextFormat = new TextFormat();
		public var txt_type3:TextFormat = new TextFormat();
		public var txt_type4:TextFormat = new TextFormat();
		public var micro_fmt:TextFormat = new TextFormat();
		
		private var _footer:FooterView = new FooterView();
		
		public function ScreenEnterUserData()
		{
			super("enter_userdata");
		}		
		
		override protected function init(e:Event):void 
		{
			super.init(e);
			
			addChild(_footer);
			
			addInputField();
			
			chekplane = new ChekPlane();
			chekplane.visible = false;
			addChild(chekplane);
			
			for (var jj:Number = 1; jj <= addplanecount; jj++)
			{
				this["addplane" + jj] = new ScalePlane(600, 580);
				this["addplane" + jj].visible = false;
				this["addplane" + jj].tab_index = jj;
				this["addplane" + jj].addEventListener(ScalePlane.ON_PLANE_CLICK, onPlaneClick);
				addChild(this["addplane" + jj]);
			}
			
			testplane = new ScalePlane(735);
			testplane.tab_index = 0;
			testplane.addEventListener(ScalePlane.ON_PLANE_CLICK, onPlaneClick);
			testplane.x = 50; // txt_x + 10;
			testplane.y = inputtxt1.y;
			addChild(testplane);
			
			fields.push(testplane);
			for (jj = 1; jj <= addplanecount; jj++)
			{
				fields.push(this["addplane" + jj])
			}
			
			pic_count = 0;
			keypad = new KeyPad();
			keypad.x = 600;
			keypad.y = 200;
			keypad.num_limit = phone_nums_limit;
			keypad.visible = false;
			addChild(keypad);
			
			keyboard = new KeyBoard();
			keyboard.x = 50;
			keyboard.y = 450;
			keyboard.num_limit = phone_nums_limit;
			addChild(keyboard);
			
			btn_next = new ButtonBase("next", 0x00FF00);
			btn_next.addEventListener(ButtonBase.ON_PRESS_UI_BUTTON, pressBtn);
			btn_next.addEventListener(ButtonBase.ON_PIC_LOADED, allPicLoaded);
			btn_next.visible = false;
			addChild(btn_next);
			pic_count++;
			
			btn_nic_d = new ButtonBase("nic_ru", 0x444444);
			btn_nic_d.addEventListener(ButtonBase.ON_PRESS_UI_BUTTON, pressBtn);
			btn_nic_d.addEventListener(ButtonBase.ON_PIC_LOADED, allPicLoaded);
			addChild(btn_nic_d);
			pic_count++;
			
			btn_nic_r = new ButtonBase("nic_ru", 0x444444);
			btn_nic_r.addEventListener(ButtonBase.ON_PRESS_UI_BUTTON, pressBtn);
			btn_nic_r.addEventListener(ButtonBase.ON_PIC_LOADED, allPicLoaded);
			addChild(btn_nic_r);
			pic_count++;
			
			keypad.addEventListener(KeyPad.KEY_PAD_RELEASED, update);
			keyboard.addEventListener(KeyPad.KEY_PAD_RELEASED, update);
		}
		
		private function onPlaneClick(e:Event):void
		{
			var indx:Number = (e.target as ScalePlane).tab_index;
			current_indx = indx + 1;
			for (var ii:Number = 0; ii < fields.length; ii++)
			{
				(fields[ii] as ScalePlane).isCheck(false);
			}
			getCurrentField().isCheck(true);
			if (current_indx == 1)
			{
				keyboard.rewrite_value = TmpModel.payment.accauntnumber;
				keypad.rewrite_value = TmpModel.payment.accauntnumber;
				if (TmpModel.payment.accauntnumber.length == 0) {
					keyboard.pressShift();
				}
			}
			else
			{
				keyboard.rewrite_value = TmpModel.payment.getExtraDataByID(current_indx - 2);
				keypad.rewrite_value = TmpModel.payment.getExtraDataByID(current_indx - 2);
				
				if (TmpModel.payment.getExtraDataByID(current_indx - 2).length == 0 && ((current_indx<8&&TmpModel.payment.provider.nextPage=="p_fio2.html")||(current_indx<5&&TmpModel.payment.provider.nextPage=="p_fio.html"))) {
					keyboard.pressShift();
				}
			}
			reDraw2();
		}
		
		private function getCurrentField():ScalePlane
		{
			return fields[current_indx - 1] as ScalePlane;
		}
		
		override public function reDraw():void
		{
			_footer.reDraw();
			
			keyboard.nullRestrickt();
			keypad.rewrite_value = TmpModel.payment.accountId;
			if (TmpModel.payment.accauntnumber.length == 0)
			{
				current_indx = 1;
				fields_count = 1;
				for (var ii:Number = 0; ii < fields.length; ii++)
				{
					(fields[ii] as ScalePlane).isCheck(false);
				}
				getCurrentField().isCheck(true);
				btn_next.visible = false;
				btn_nic_d.visible = false;
				btn_nic_r.visible = false;
				chekplane.visible = false;
				testplane.swReady = false;
				for (var jj:Number = 1; jj <= addplanecount; jj++)
				{
					(this["addplane" + jj] as ScalePlane).swReady = false;
				}
				
			}
			reDraw2();
		}
		
		private function testFieldString(str:String = ""):Boolean
		{
			var test:Boolean = validateRegularExpression(new RegExp(TmpModel.payment.provider.providerXML.@regex), TmpModel.payment.accauntnumber);
			return test;
			
			if (TmpModel.payment.provider.providerXML.@regex.length > 0)
			{
				var test:Boolean = validateRegularExpression(new RegExp(TmpModel.payment.provider.providerXML.@regex), testplane.prefix_txt.text.concat(TmpModel.payment.accauntnumber));
				return test;
			}
			if (TmpModel.payment.provider.nextPage == "p_phone.html")
			{
				return (TmpModel.payment.accauntnumber.length==10);
			}			
			if (TmpModel.payment.provider.nextPage == "p_card.html")
			{
				return testLUNA(TmpModel.payment.accauntnumber);
			}
			
			if (TmpModel.payment.provider.nextPage == "p_zhkumsk.html")
			{
				var str:String = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_extra_period"));
				var month:String = str.substr(0, 2);
				var year:String = str.substr(2);
				if (Number(month) < 1 || Number(month) > 12)
					return false;
				if (year.length < 2 || Number(year) > 20)
					return false;
			}
			return true;
		}
		
		private function testLUNA(str:String):Boolean
		{
			var summ:Number = 0;
			if (str.length < 16)
				return false;
			for (var ii:Number = 1; ii <= 16; ii++)
			{
				if (ii % 2 == 0)
				{ //чет
					var num:Number = Number(str.charAt(16 - ii)) * 2;
					summ += (num > 9) ? (Number(num.toString().charAt(0)) + Number(num.toString().charAt(1))) : num;
				}
				else
				{ //нечет
					summ += Number(str.charAt(16 - ii));
				}
			}
			return (summ % 10 == 0);
		}
		
		private function testFieldSymbolCount(entered_count:Number):Boolean
		{
				var test:Boolean = validateRegularExpression(new RegExp(TmpModel.payment.provider.providerXML.@regex), TmpModel.payment.accauntnumber);
				return test;
				
			if (TmpModel.payment.provider.providerXML.@regex.length > 0)
			{
				var test:Boolean = validateRegularExpression(new RegExp(TmpModel.payment.provider.providerXML.@regex), testplane.prefix_txt.text.concat(TmpModel.payment.accauntnumber));
				return test;
			}
			if (entered_count >= acc_number_length)
			{
				return true;
			}
			else if (entered_count >= acc_number_min_length && acc_number_min_length > -1)
			{
				return true;
			}
			if (acc_number_min_length == 0) return true;
			return false;
		}
		
		private function update(e:Event):void
		{
			//if (KeyBoard.MAGIC && (TmpModel.payment.provider.nextPage == "p_fio2.html" || TmpModel.payment.provider.nextPage == "p_fio.html")) {
				//if (readSavedData()) {
					//current_indx = 1;
					//(e.target as KeyBoard).rewrite_value = TmpModel.payment.accauntnumber;
				//}
			//}
			if (current_indx == 1)
			{
				if (keyboard.visible)
				{
					if ((e.target as KeyBoard).entered_value.length <= acc_number_length)
					{
						TmpModel.payment.accauntnumber = (e.target as KeyBoard).entered_value;
						if (testFieldSymbolCount(TmpModel.payment.accauntnumber.length)) getCurrentField().swReady = true;
						if (TmpModel.payment.accauntnumber.length==0) {
							keyboard.pressShift();
						}
					}
				}
				else
				{
					if ((e.target as KeyPad).entered_value.length <= acc_number_length)
					{
						TmpModel.payment.accauntnumber = (e.target as KeyPad).entered_value;
					}
				}
			}
			else
			{
				if (keyboard.visible)
				{
					TmpModel.payment.writeExtrDataByID(current_indx - 2, (e.target as KeyBoard).entered_value);
					if (TmpModel.payment.getExtraDataByID(current_indx - 2).length == 0 && ((current_indx<8&&TmpModel.payment.provider.nextPage=="p_fio2.html")||(current_indx<5&&TmpModel.payment.provider.nextPage=="p_fio.html"))) {
						keyboard.pressShift();
					}
				}
				else
				{
					TmpModel.payment.writeExtrDataByID(current_indx - 2, (e.target as KeyPad).entered_value);
				}
			}
			getCurrentField().swReady = false;
			if (current_indx == 1)
			{
				if (fields_count == 1)
				{
					btn_next.visible = false;
					if (testFieldSymbolCount(TmpModel.payment.accauntnumber.length))
					{
						btn_next.visible = testFieldString(TmpModel.payment.accauntnumber);
						getCurrentField().swReady = btn_next.visible;
					}
				}
				else if ((TmpModel.payment.accauntnumber.length >= acc_number_length))
				{
					getCurrentField().swReady = true;
					getCurrentField().isCheck(false);
					current_indx++;
					getCurrentField().isCheck(true);
					keyboard.rewrite_value = TmpModel.payment.getExtraDataByID(current_indx - 2);
					keypad.rewrite_value = TmpModel.payment.getExtraDataByID(current_indx - 2);
				}
				else if (TmpModel.payment.accauntnumber.length >= acc_number_min_length && getCurrentField().getMask() == 0) {
					getCurrentField().swReady = true;
				}
			}
			else
			{
				if (current_indx == fields_count)
				{
					btn_next.visible = false;
					if (testFieldSymbolCount(TmpModel.payment.getExtraDataLengthByID(current_indx - 2)))
					{
						btn_next.visible = testFieldString();
						getCurrentField().swReady = btn_next.visible;
						
					}
				}
				else if ((TmpModel.payment.getExtraDataLengthByID(current_indx - 2) >= acc_number_length))
				{
					getCurrentField().swReady = true;
					getCurrentField().isCheck(false);
					current_indx++;
					getCurrentField().isCheck(true);
					keyboard.rewrite_value = TmpModel.payment.getExtraDataByID(current_indx - 2);
					keypad.rewrite_value = TmpModel.payment.getExtraDataByID(current_indx - 2);
					if (getCurrentField().getMask() == 0 && TmpModel.payment.getExtraDataLengthByID(current_indx - 2) == 0) keyboard.pressShift();
					btn_next.visible = chekAllFields();
				}else if (TmpModel.payment.getExtraDataLengthByID(current_indx - 2) >= acc_number_min_length && getCurrentField().getMask()==0) {
					getCurrentField().swReady = true;
				}
				else if (chekAllFields())
				{
					btn_next.visible = true;
				}
			}
			if (chekAllFields())
			{
				btn_next.visible = true;
			}
			
			reDraw2();
		}
		
		private function chekAllFields():Boolean
		{
			if (!testplane.swReady)
				return false;
			for (var ii:Number = 1; ii <= addplanecount; ii++)
			{
				if ((this["addplane" + ii] as ScalePlane).visible && !(this["addplane" + ii] as ScalePlane).swReady)
					return false;
			}
			return true;
		}
		
		public function prepareDataToConfirm():void
		{
			//TmpModel.userInfo.confirm_string = TmpModel.payment.accauntnumber;
			var str:String
			var fio:String
			var _i:String
			var _o:String
			if (TmpModel.payment.provider.nextPage == "p_card.html")
			{
				var acc_num:String;
				var card:String = TmpModel.payment.accauntnumber;
				var extra_card:String = card.substr(0, 4) + "" + card.substr(4, 4) + "" + card.substr(8, 4) + "" + card.substr(12, 4);
				TmpModel.payment.addExtraDataField("_extra_card", extra_card);
				TmpModel.payment.accauntnumber = card.substr(0, 4) + "-****-****-" + card.substr(12, 4);
				//TmpModel.userInfo.confirm_string = TmpModel.payment.accauntnumber;
			}
			else if (TmpModel.payment.provider.nextPage == "p_phone.html" || TmpModel.payment.provider.nextPage == "p_mgts.html")
			{
				//TmpModel.userInfo.confirm_string = testplane.getText();
			}
			else if (TmpModel.payment.provider.nextPage == "p_ru_center.html")
			{
				//TmpModel.payment.accauntnumber = TmpModel.userInfo.confirm_string = testplane.getText();
			}
			else if (TmpModel.payment.provider.nextPage == "p_zhkumsk.html")
			{
				if (TmpModel.payment.getExtraDataIDByName("_extra_ins") == -1)
				{
					TmpModel.payment.addExtraDataField("_extra_ins", "");
				}
				var ins:Number = chekplane.swChek ? 1 : 0;
				TmpModel.payment.writeExtrDataByID(TmpModel.payment.getExtraDataIDByName("_extra_ins"), ins.toString());
			}
			else if (TmpModel.payment.provider.nextPage == "p_samgu.html")
			{
				var student_io:String = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("student_io"));
				var student:String = TmpModel.payment.accauntnumber;
				var payer:String = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_extra_ssp_payer"));
				var payer_io:String = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("payer_io"));
				var dogovor_date:String = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_extra_ssp_date"));
				var dogovor_number:String = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_extra_ssp_account"));
				
				student = student.concat(" " + student_io.charAt(0) + ". " + student_io.charAt(1) + ".");
				TmpModel.payment.accauntnumber = student;
				//TmpModel.userInfo.confirm_string = student;
				if (payer.length > 0)
				{
					payer = payer.concat(" " + payer_io.charAt(0) + ". " + payer_io.charAt(1) + ".");
					TmpModel.payment.writeExtrDataByID(TmpModel.payment.getExtraDataIDByName("_extra_ssp_payer"), payer);
				}
				dogovor_date = "20" + dogovor_date.substr(4) + "" + dogovor_date.substr(2, 2) + "" + dogovor_date.substr(0, 2);
				TmpModel.payment.writeExtrDataByID(TmpModel.payment.getExtraDataIDByName("_extra_ssp_date"), dogovor_date);
				
				var for_print:String = "\r\nНомер договора: " + dogovor_number + "\r\nДата договора: " + dogovor_date.substr(6) + "." + dogovor_date.substr(4, 2) + ".20" + dogovor_date.substr(2, 2) + "" + ((payer.length != 0) ? "\r\nПлательщик: " + payer : "");
				
				if (TmpModel.payment.getExtraDataIDByName("_extra_receipt_prt_bottom_reklama") == -1)
				{
					TmpModel.payment.addExtraDataField("_extra_receipt_prt_bottom_reklama", for_print);
				}
				
			}
			else if (TmpModel.payment.provider.nextPage == "p_stream.html")
			{
				TmpModel.payment.accauntnumber = testplane.getText();
			}else if (TmpModel.payment.provider.nextPage == "p_fio2.html") 
			{
				str = "обл." + addplane3.getText() +
				",р-н."+addplane4.getText()+
				",г/с/д."+addplane5.getText()+
				",ул." +addplane6.getText()+
				",д."+addplane7.getText()+
				",стр."+addplane8.getText()+
				",кв." +addplane9.getText() ;
				fio = TmpModel.payment.accauntnumber;
				//var io:String = TmpModel.userInfo.getExtraDataByID(TmpModel.userInfo.getExtraDataIDByName("payer_io"));
				_i = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("payer_io")).charAt(0).toUpperCase();
				_o = addplane2.getText().charAt(0).toUpperCase();
				fio = fio.concat(" " + _i+". "+_o+".");// io.charAt(0).toUpperCase() + ". " + io.charAt(1).toUpperCase() + ".");
				TmpModel.payment.accauntnumber = fio;
				//TmpModel.userInfo.confirm_string = fio;
				TmpModel.payment.addExtraDataField("_extra_address", str);
			}else if (TmpModel.payment.provider.nextPage == "p_fio.html") 
			{
				str = "ул." +addplane3.getText()+
				",д."+addplane4.getText()+
				",стр."+addplane5.getText()+
				",кв." +addplane6.getText() ;
				fio = TmpModel.payment.accauntnumber;
				//var io:String = TmpModel.userInfo.getExtraDataByID(TmpModel.userInfo.getExtraDataIDByName("payer_io"));
				_i = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("payer_io")).charAt(0).toUpperCase();
				_o = addplane2.getText().charAt(0).toUpperCase();
				fio = fio.concat(" " + _i+". "+_o+".");// io.charAt(0).toUpperCase() + ". " + io.charAt(1).toUpperCase() + ".");
				TmpModel.payment.accauntnumber = fio;
				TmpModel.payment.addExtraDataField("_extra_address", str);
			}
			if (testplane.prefix_txt.text.length > 0 && testplane.prefix_txt.visible)
			{
				TmpModel.payment.accauntnumber = testplane.prefix_txt.text.concat(TmpModel.payment.accauntnumber);
				//TmpModel.userInfo.confirm_string = TmpModel.payment.accauntnumber;
			}
		}
		
		//private function saveDataToSO():void 
		//{
			//var str:String;
			//str = testplane.getText();
			//for (var ii:Number = 1; ii < fields_count; ii++) {
				//str += "|" + (this["addplane" + ii] as ScalePlane).getText();
			//}
			//if (TmpModel.payment.provider.nextPage == "p_fio2.html") TmpModel.writeDataToSO(str);
			//else  TmpModel.writeDataToSO(str, "magic2");
		//}
		
		//private function readSavedData():Boolean 
		//{
			//var str:String;
			//str = TmpModel.readDataFromSO("");
			//if (str == null) return false;
			//var arr:Array = str.split("|");
			//if (arr.length < fields_count-2) return false;
			//TmpModel.payment.accauntnumber = arr[0];
			//testplane.swReady = true;
			//for (var ii:Number = 0; ii < fields_count-1; ii++ ) {
				//TmpModel.payment.writeExtrDataByID(ii, arr[ii + 1]);
				//(this["addplane" + (ii + 1)] as ScalePlane).swReady = true;
			//}
			//return true;
		//}
		
		public function addInputField():void
		{
			var txt_x:Number = 150;
			var txt_y:Number = 410; //310;
			
			txt_type = TmpModel.getTextFormat(52, 0x676767,true);
			txt_type.letterSpacing = 7;
			
			txt_type2 = TmpModel.getTextFormat(52, 0xFFFFFF,true);
			
			txt_type3 = TmpModel.getTextFormat(38, 0x676767,true);
			txt_type3.letterSpacing = 1;
			
			small_format = TmpModel.getTextFormat(24, 0x676767,true);
			small_format.letterSpacing = 1;
			
			micro_fmt = TmpModel.getTextFormat(16, 0x676767,true);
			micro_fmt.letterSpacing = 1;
			
			txt_type4 = TmpModel.getTextFormat(16, 0x676767,true);
			
			inputtxt0 = new TextField();
			inputtxt0.embedFonts = true;
			inputtxt0.y = txt_y;
			inputtxt0.x = txt_x + 10;
			inputtxt0.width = 54;
			inputtxt0.height = 85;
			inputtxt0.border = false;
			inputtxt0.selectable = false;
			inputtxt0.defaultTextFormat = txt_type2;
			inputtxt0.antiAliasType = AntiAliasType.ADVANCED;
			inputtxt0.thickness = 100;
			
			inputtxt1 = new TextField();
			inputtxt1.embedFonts = true;
			inputtxt1.y = txt_y - 5;
			inputtxt1.x = txt_x + 10;
			
			inputtxt1.width = 545;
			inputtxt1.height = 75;
			inputtxt1.border = false;
			inputtxt1.selectable = false;
			inputtxt1.defaultTextFormat = txt_type;
			inputtxt1.antiAliasType = AntiAliasType.ADVANCED;
			
			inputtxt2 = new TextField();
			inputtxt2.embedFonts = true;
			inputtxt2.y = txt_y;
			inputtxt2.x = inputtxt1.x + inputtxt1.width + 15;
			inputtxt2.width = 350;
			inputtxt2.height = 85;
			inputtxt2.border = false;
			inputtxt2.selectable = false;
			inputtxt2.defaultTextFormat = txt_type;
			inputtxt2.antiAliasType = AntiAliasType.ADVANCED;
			
			up_txt = new TextField();
			up_txt.embedFonts = true;
			up_txt.y = txt_y - 20 - 100;
			up_txt.x = 250; // txt_x + 15;
			up_txt.width = 550;
			up_txt.defaultTextFormat = txt_type3;
			up_txt.antiAliasType = AntiAliasType.ADVANCED;
			up_txt.thickness = -50;
			up_txt.height = 140;
			up_txt.multiline = true;
			up_txt.text = up_txt_str;
			addChild(up_txt);
			
			down_txt = new TextField();
			down_txt.embedFonts = true;
			down_txt.defaultTextFormat = txt_type3;
			down_txt.width = 550;
			down_txt.htmlText = down_txt_str;
			down_txt.x = up_txt.x;
			down_txt.y = txt_y + 85;
			down_txt.thickness = -50;
			down_txt.antiAliasType = AntiAliasType.ADVANCED;
			down_txt.visible = false;
			
			txt1 = new TextField();
			txt1.embedFonts = true;
			txt1.defaultTextFormat = txt_type3;
			txt1.width = 550;
			txt1.htmlText = txt1_str;
			txt1.x = up_txt.x;
			txt1.y = txt_y + 85;
			txt1.thickness = -50;
			txt1.antiAliasType = AntiAliasType.ADVANCED;
			txt1.visible = false;
			
			addChild(down_txt);
			addChild(txt1);
			
			pics_info = pics_info.reverse();
			loadPictures();
		}
		
		//private var efd:ExtraFieldsData = new ExtraFieldsData();
		
		public function reDraw2():void
		{
			var ph:String = TmpModel.payment.accauntnumber;
			up_txt.defaultTextFormat = txt_type3;
			up_txt.x = 250;
			down_txt.defaultTextFormat = txt_type3;
			txt1.defaultTextFormat = txt_type3;
			var txt_y:Number = 410; //310;
			acc_number_min_length = -1;
			prv_logo.ph_provider2 = TmpModel.payment.provider.providerXML;
			prv_logo.visible = true;
			testplane.prefix = "";
			testplane.scaleX = 1;
			testplane.scaleY = 1;
			addplane1.prefix = "";
			keyboard.x = 50;
			keyboard.y = 450;
			for (var jj:Number = 1; jj <= addplanecount; jj++)
			{
				this["addplane" + jj].visible = false;
				(this["addplane" + jj] as ScalePlane).scaleX = 1;
				(this["addplane" + jj] as ScalePlane).scaleY = 1;
			}
			
			down_txt.visible = false;
			txt1.visible = false;
			keypad.num_limit = acc_number_length = TmpModel.payment.provider.providerXML.@length;
			if (acc_number_length == 0)
			{
				keypad.num_limit = acc_number_length = 30;
				acc_number_min_length = 1;
			}
			
			if (TmpModel.payment.provider.nextPage == "p_universal_kb.html")
			{
				fields_count = 1;
				keypad.visible = false;
				keyboard.visible = true;
				keyboard.reDrawKeyBoard();
				up_txt_str = "Введите номер \nдоговора/лицевого счета";
				inputtxt1.y = 355;
				testplane.y = 340;
				prv_logo.y = 200;
				up_txt.y = txt_y - 20 - 180;
			}
			else
			{
				inputtxt1.y = 405;
				testplane.y = 405;
				addplane1.visible = false;
				prv_logo.y = 250;
				up_txt.y = txt_y - 40 - 100;
				keyboard.visible = false;
				keypad.visible = true;
				if (TmpModel.payment.provider.nextPage == "p_money.html" || TmpModel.payment.provider.nextPage == "p_money2.html")
				{
					//up_txt_str = "Введите номер \nкошелька (" + TmpModel.userInfo.getPhonePrv().acc_length + " цифр)";
					up_txt_str = "Введите номер \nкошелька (" + TmpModel.payment.provider.providerXML.@length + " цифр)";
				}
				else if (TmpModel.payment.provider.nextPage == "p_phone.html" || TmpModel.payment.provider.nextPage == "p_cellular_sng.html")
				{
					up_txt_str = "Введите номер телефона";
				}
				else
				{
					up_txt_str = "Введите номер \nдоговора/лицевого счета";
				}
				
				testplane.setMaskOnField(0);
				//var rgx:String = TmpModel.userInfo.getPhonePrv().regex;
				var rgx:String = TmpModel.payment.provider.providerXML.@regex;
				if (TmpModel.payment.provider.nextPage == "p_cellular_sng.html")
				{
					fields_count = 1;
					addplane1.visible = false;
					//acc_number_length = TmpModel.userInfo.getPhonePrv().acc_length;
					acc_number_length = TmpModel.payment.provider.providerXML.@length;
					if (!isNaN(parseInt(rgx.charAt(0))))
					{
						var ii:Number = 1;
						while (!isNaN(parseInt(rgx.charAt(ii))))
							ii++;
						
						testplane.prefix = rgx.substr(0, ii);
						var symbol_length:Number = 45;
						testplane.reScale(testplane.curr_plane_wd(), testplane.curr_plane_wd() - 18 - symbol_length * ii, 15 + symbol_length * ii);
						//acc_number_length = TmpModel.userInfo.getPhonePrv().acc_length - ii;
						acc_number_length = TmpModel.payment.provider.providerXML.@length - ii;
					}
				}
				else if (TmpModel.payment.provider.nextPage == "p_money.html" || TmpModel.payment.provider.nextPage == "p_money2.html")
				{
					testplane.x = 60;
					testplane.reScale(740);
					//keypad.num_limit = acc_number_length = TmpModel.userInfo.getPhonePrv().acc_length;
					keypad.num_limit = acc_number_length = TmpModel.payment.provider.providerXML.@length;
					if (TmpModel.payment.provider.nextPage == "p_money2.html")
					{
						fields_count = 2;
						TmpModel.payment.addExtraDataField("_extra_ssp_account", "");
						addplane1.visible = true;
						addplane1.setMaskOnField(1);
						addplane1.reScale(740);
						addplane1.x = testplane.x;
						addplane1.y = testplane.y + testplane.height + 50;
						addplane1.prefix = "";
						addplane1.text = TmpModel.payment.getExtraDataByID(0);
						if (current_indx == 1)
						{
							//keypad.num_limit = acc_number_length = TmpModel.userInfo.getPhonePrv().acc_length;
							keypad.num_limit = acc_number_length = TmpModel.payment.provider.providerXML.@length;
						}
						else
						{
							keypad.num_limit = acc_number_length = 10;
						}
						
					}
					else
					{
						fields_count = 1;
						addplane1.visible = false;
						if (rgx.charAt(0) == "Z")
						{
							testplane.prefix = "Z";
							testplane.reScale(740, 670, 65);
							//keypad.num_limit = acc_number_length = TmpModel.userInfo.getPhonePrv().acc_length - 1;
							keypad.num_limit = acc_number_length = TmpModel.payment.provider.providerXML.@length - 1;
							//up_txt_str = "Введите номер \nкошелька (" + (TmpModel.userInfo.getPhonePrv().acc_length - 1) + " цифр)";
							up_txt_str = "Введите номер \nкошелька (" + (TmpModel.payment.provider.providerXML.@length - 1) + " цифр)";
						}
						else
						{
							testplane.prefix = "";
							testplane.reScale(740);
							//keypad.num_limit = acc_number_length = TmpModel.userInfo.getPhonePrv().acc_length;
							keypad.num_limit = acc_number_length = TmpModel.payment.provider.providerXML.@length;
						}
					}
				}
				else if (TmpModel.payment.provider.nextPage == "p_card.html")
				{
					testplane.x = 60;
					testplane.reScale(740);
					testplane.setMaskOnField(2);
					if (TmpModel.payment.getExtraDataIDByName("_extra_phone") == -1)
					{
						TmpModel.payment.addExtraDataField("_extra_phone", "");
						fields_count = 2;
					}
					addplane1.visible = true;
					addplane1.x = testplane.x;
					addplane1.y = testplane.y + testplane.height + 50;
					addplane1.prefix = "";
					addplane1.setMaskOnField(1);
					addplane1.reScale(740);
					addplane1.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_extra_phone"));
					acc_number_length = 16;
					if (current_indx == 1)
					{
						setLimits(16, 16, 16);
					}
					else
					{
						setLimits(10, 10, 10);
					}
				}
				else if (TmpModel.payment.provider.nextPage == "p_phone.html")
				{
					addplane1.visible = false;
					current_indx = 1;
					fields_count = 1;
					TmpModel.payment.clearExtraData();
					testplane.x = 50;
					testplane.setMaskOnField(1);
					testplane.prefix = "";
					testplane.reScale(740);
					keypad.num_limit = acc_number_length = 10;
				}
				else if (TmpModel.payment.provider.nextPage == "p_mgts.html")
				{
					up_txt_str = "Введите номер телефона \n / № квартиры";
					testplane.x = 50;
					testplane.setMaskOnField(1);
					testplane.reScale(550);
					addplane1.x = testplane.x + testplane.width - 24;
					addplane1.y = testplane.y;
					addplane1.setMaskOnField(0);
					addplane1.visible = true;
					addplane1.prefix = "/";
					addplane1.reScale(240, 170, 55);
					if (TmpModel.payment.getExtraDataIDByName("_extra_flat") == -1)
					{
						TmpModel.payment.addExtraDataField("_extra_flat", "");
						fields_count = 2;
					}
					if (current_indx == 1)
					{
						keypad.num_limit = 10;
						acc_number_length = 10;
					}
					else
					{
						setLimits(4, 4, 1);
					}
					
					addplane1.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_extra_flat"));
					
				}
				else if (TmpModel.payment.provider.nextPage == "p_gazprom.html")
				{
					up_txt.defaultTextFormat = small_format;
					down_txt.defaultTextFormat = small_format;
					up_txt_str = "Введите номер лицевого счета";
					down_txt.visible = true;
					down_txt_str = "Введите показания счетчика";
					
					testplane.x = 250;
					testplane.setMaskOnField(0);
					testplane.y = up_txt.y + up_txt.height - 80;
					testplane.reScale(550);
					down_txt.y = testplane.y + testplane.height;
					addplane1.x = testplane.x;
					addplane1.y = down_txt.y + down_txt.height - 50;
					addplane1.visible = true;
					addplane1.prefix = "";
					addplane1.setMaskOnField(0);
					addplane1.reScale(280);
					addplane1.swReady = true;
					
					if (TmpModel.payment.getExtraDataIDByName("_extra_ssp_account") == -1)
					{
						TmpModel.payment.addExtraDataField("_extra_ssp_account", "");
						fields_count = 2;
					}
					if (current_indx == 1)
					{
						//setLimits(TmpModel.userInfo.getPhonePrv().acc_length, TmpModel.userInfo.getPhonePrv().acc_length, 3);
						setLimits(TmpModel.payment.provider.providerXML.@length, TmpModel.payment.provider.providerXML.@length, 3);
					}
					else
					{
						setLimits(6, 6, 0);
					}
					
					addplane1.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_extra_ssp_account"));
				}
				else if (TmpModel.payment.provider.nextPage == "p_mes.html")
				{
					addplane1.visible = false;
					up_txt_str = "Введите № абонента";
					testplane.x = 50;
					testplane.setMaskOnField(3);
					testplane.reScale(550);
					keypad.num_limit = acc_number_length = 10;
					if (TmpModel.payment.getExtraDataIDByName("_extra_period") == -1)
					{
						var dt:Date = new Date();
						var month:String = Number(dt.getMonth() + 1).toString();
						if (month.length == 1)
							month = "0" + month;
						var year:String = dt.getFullYear().toString().substr(2);
						var str:String = month.concat(year);
						TmpModel.payment.addExtraDataField("_extra_period", str);
					}
				}
				else if (TmpModel.payment.provider.nextPage == "p_samgu.html")
				{
					keypad.visible = false;
					keyboard.visible = true;
					keyboard.y = 470;
					
					var fscale:Number = 0.85;
					for (jj = 1; jj <= 5; jj++)
					{
						(this["addplane" + jj] as ScalePlane).visible = true;
						(this["addplane" + jj] as ScalePlane).scaleX = fscale;
						(this["addplane" + jj] as ScalePlane).scaleY = fscale;
					}
					
					testplane.x = 280;
					testplane.y = 180;
					testplane.scaleX = fscale;
					testplane.scaleY = fscale;
					testplane.reScale(550);
					
					addplane1.reScale(180);
					addplane1.x = testplane.x + testplane.width + 90;
					addplane1.y = testplane.y;
					addplane1.setMaskOnField(5);
					
					addplane2.reScale(410);
					addplane2.x = testplane.x + 20;
					addplane2.y = testplane.y + testplane.height + 5;
					
					addplane3.reScale(400);
					addplane3.x = addplane2.x + addplane2.width + 45;
					addplane3.y = addplane2.y;
					addplane3.setMaskOnField(6);
					
					addplane4.reScale(550);
					addplane4.x = testplane.x;
					addplane4.y = addplane3.y + addplane3.height + 5;
					
					addplane5.reScale(180);
					addplane5.x = addplane4.x + addplane4.width + 90;
					addplane5.y = addplane4.y;
					addplane5.setMaskOnField(5);
					
					up_txt.defaultTextFormat = micro_fmt;
					up_txt.embedFonts = true;
					up_txt.x = testplane.x;
					up_txt.y = testplane.y - 25;
					up_txt.width = 850;
					up_txt_str = "Фамилия студента                                                                     И.О.(Инициалы)";
					down_txt.visible = true;
					down_txt.defaultTextFormat = micro_fmt;
					down_txt.x = up_txt.x + 30;
					down_txt.y = addplane2.y - 25;
					down_txt_str = "Номер договора                                          Дата договора";
					
					txt1.visible = true;
					txt1.defaultTextFormat = micro_fmt;
					txt1.x = up_txt.x;
					txt1.width = 850;
					txt1.y = addplane4.y - 25;
					txt1_str = "Фамилия плательщика                                                              И.О.(Инициалы)";
					
					fields_count = 6;
					
					if (TmpModel.payment.getExtraDataIDByName("student_io") == -1)
					{
						TmpModel.payment.addExtraDataField("student_io", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_extra_ssp_account") == -1)
					{
						TmpModel.payment.addExtraDataField("_extra_ssp_account", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_extra_ssp_date") == -1)
					{
						TmpModel.payment.addExtraDataField("_extra_ssp_date", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_extra_ssp_payer") == -1)
					{
						TmpModel.payment.addExtraDataField("_extra_ssp_payer", "");
						addplane4.swReady = true;
					}
					if (TmpModel.payment.getExtraDataIDByName("payer_io") == -1)
					{
						TmpModel.payment.addExtraDataField("payer_io", "");
						addplane5.swReady = true;
					}
					
					addplane1.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("student_io"));
					addplane2.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_extra_ssp_account"));
					addplane3.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_extra_ssp_date"));
					addplane4.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_extra_ssp_payer"));
					addplane5.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("payer_io"));
					keyboard.nullRestrickt();
					if (current_indx == 1)
					{
						setLimits(25, 25, 1);
					}
					else if (current_indx == 2)
					{
						setLimits(2, 2, 2);
					}
					else if (current_indx == 3)
					{
						setLimits(10, 10, 1);
					}
					else if (current_indx == 4)
					{
						keyboard.setRestrickt("0-9");
						setLimits(6, 6, 6);
					}
					else if (current_indx == 5)
					{
						setLimits(25, 25, 0);
					}
					else if (current_indx == 6)
					{
						setLimits(2, 2, 0);
					}
					
				}
				else if (TmpModel.payment.provider.nextPage == "p_zhkumsk.html")
				{
					
					up_txt_str = "Номер абонента";
					up_txt.y = 230;
					down_txt.visible = true;
					down_txt.width = 700;
					down_txt.y = 470;
					down_txt.x = 50;
					down_txt_str = "Период (ММГГ)                                Страховка";
					up_txt.defaultTextFormat = small_format;
					down_txt.defaultTextFormat = small_format;
					
					testplane.x = 280;
					up_txt.x = testplane.x;
					testplane.y = 270;
					testplane.reScale(500);
					
					chekplane.visible = true;
					chekplane.x = testplane.x + testplane.width - chekplane.width + 20;
					chekplane.y = testplane.y + testplane.height + 50
					
					addplane1.visible = true;
					addplane1.setMaskOnField(0);
					addplane1.reScale(230);
					addplane1.x = testplane.x;
					addplane1.y = chekplane.y;
					if (TmpModel.payment.getExtraDataIDByName("_extra_period") == -1)
					{
						TmpModel.payment.addExtraDataField("_extra_period", "");
						fields_count = 2;
					}
					if (current_indx == 1)
					{
						setLimits(10, 10, 1);
					}
					else
					{
						keypad.num_limit = 4;
						acc_number_length = 4;
					}
					addplane1.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_extra_period"));
					
				}
				else if (TmpModel.payment.provider.nextPage == "p_ru_center.html")
				{
					keypad.num_limit = acc_number_length = 6;
					testplane.reScale(700);
					testplane.setMaskOnField(4);
					btn_nic_d.visible = true;
					btn_nic_r.visible = true;
					ph = ph.concat("/");
					ph = ph.concat(nic_value);
				}
				else if (TmpModel.payment.provider.nextPage == "p_stream.html")
				{
					keypad.num_limit = acc_number_length = 8;
					testplane.setMaskOnField(7);
				}else if (TmpModel.payment.provider.nextPage == "p_fio2.html")
				{
					prv_logo.visible = false;
					keypad.visible = false;
					keyboard.visible = true;
					keyboard.y = 470;
					
					fscale = 0.6;
					for (jj = 1; jj <= 9; jj++)
					{
						(this["addplane" + jj] as ScalePlane).visible = true;
						(this["addplane" + jj] as ScalePlane).scaleX = fscale;
						(this["addplane" + jj] as ScalePlane).scaleY = fscale;
					}
					
					testplane.x = 50;//фамилия
					testplane.y = 180;
					testplane.scaleX = fscale;
					testplane.scaleY = fscale;
					testplane.setMaskOnField(0);
					testplane.reScale(500);
					
					addplane1.reScale(120);//Имя(инициал)
					addplane1.x = testplane.x + testplane.width + 50;
					addplane1.y = testplane.y;
					addplane1.setMaskOnField(0);

					addplane2.reScale(120);//Отчество(инициал)
					addplane2.x = addplane1.x + addplane1.width + 70;
					addplane2.y = addplane1.y;
					addplane2.setMaskOnField(0);
					
					addplane3.reScale(600);//Регион
					addplane3.x = testplane.x;
					addplane3.y = testplane.y + testplane.height + 20;
					addplane3.setMaskOnField(0);
					
					addplane4.reScale(600);//Район
					addplane4.x = addplane3.x + addplane3.width + 20;// testplane.x;
					addplane4.y = testplane.y + testplane.height+20;
					addplane4.setMaskOnField(0);
					
					addplane5.reScale(600);//Населенный пункт
					addplane5.x = addplane4.x + addplane4.width+20;
					addplane5.y = addplane4.y;
					addplane5.setMaskOnField(0);
					
					addplane6.reScale(700);//Улица
					addplane6.x = testplane.x;
					addplane6.y = addplane5.y+addplane5.height+20;
					addplane6.setMaskOnField(0);
					
					addplane7.reScale(180);//Дом
					addplane7.x = addplane6.x + addplane6.width + 40;
					addplane7.y = addplane6.y;
					addplane7.setMaskOnField(0);
					
					addplane8.reScale(180);//Корпус
					addplane8.x = addplane7.x + addplane7.width + 40;
					addplane8.y = addplane7.y;
					addplane8.setMaskOnField(0);
					
					addplane9.reScale(180);//Квартира
					addplane9.x = addplane8.x + addplane8.width + 40;
					addplane9.y = addplane8.y;
					addplane9.setMaskOnField(0);

					
					up_txt.defaultTextFormat = micro_fmt;
					up_txt.embedFonts = true;
					up_txt.x = testplane.x;
					up_txt.y = testplane.y - 25;
					up_txt.width = 850;
					up_txt_str = "Фамилия                                              Имя (инициал)   Отчество (инициал) ";
					down_txt.visible = true;
					down_txt.defaultTextFormat = micro_fmt;
					down_txt.x = up_txt.x;
					down_txt.y = addplane5.y - 25;
					down_txt.width = 1100;
					down_txt_str = "Регион (область, край, респ)                    Район (если есть)                                      Город (населенный пункт)";
					
					txt1.visible = true;
					txt1.defaultTextFormat = micro_fmt;
					txt1.x = up_txt.x;
					txt1.width = 850;
					txt1.y = addplane7.y - 25;
					txt1_str = "Улица                                                                       Дом                    Корпус               Квартира";
					
					fields_count = 10;
					
					if (TmpModel.payment.getExtraDataIDByName("payer_io") == -1)
					{
						TmpModel.payment.addExtraDataField("payer_io", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address1") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address1", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address2") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address2", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address3") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address3", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address4") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address4", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address5") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address5", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address6") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address6", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address7") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address7", "");
					}
					
					addplane1.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("payer_io"));
					addplane2.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address"));
					addplane3.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address1"));
					addplane4.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address2"));
					addplane5.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address3"));
					addplane6.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address4"));
					addplane7.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address5"));
					addplane8.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address6"));
					addplane9.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address7"));
					keyboard.nullRestrickt();
					addplane3.swReady = true;
					addplane4.swReady = true;
					addplane8.swReady = true;
					addplane9.swReady = true;
					//keyboard.switchLanguageTo("rus");
					if (current_indx == 1)
					{
						setLimits(25, 25, 1);
					}
					else if (current_indx == 2)
					{
						setLimits(1, 1, 1);
					}
					else if (current_indx == 3)
					{
						setLimits(1, 1, 1);
					}
					else if (current_indx == 4)
					{
						setLimits(50, 50, 0);
					}
					else if (current_indx == 5)
					{
						setLimits(50, 50, 0);
					}
					else if (current_indx == 6)
					{
						setLimits(50, 50, 1);
					}
					else if (current_indx == 7)
					{
						setLimits(50, 50, 1);
					}
					else if (current_indx == 8)
					{
						setLimits(4, 4, 1);
					}else if (current_indx == 9)
					{
						setLimits(4, 4, 0);
					}else if (current_indx == 10)
					{
						setLimits(4, 4, 0);
					}
				}else if (TmpModel.payment.provider.nextPage == "p_fio.html")
				{
					prv_logo.visible = false;
					keypad.visible = false;
					keyboard.visible = true;
					keyboard.y = 470;
					
					fscale = 0.7;
					for (jj = 1; jj <= 6; jj++)
					{
						(this["addplane" + jj] as ScalePlane).visible = true;
						(this["addplane" + jj] as ScalePlane).scaleX = fscale;
						(this["addplane" + jj] as ScalePlane).scaleY = fscale;
					}
					
					testplane.x = 50;//фамилия
					testplane.y = 230;
					testplane.reScale(500);
					testplane.scaleX = fscale;
					testplane.scaleY = fscale;
					testplane.setMaskOnField(0);
					
					addplane1.reScale(120);//Имя(инициал)
					addplane1.x = testplane.x + testplane.width + 50;
					addplane1.y = testplane.y;
					addplane1.setMaskOnField(0);

					addplane2.reScale(120);//Отчество(инициал)
					addplane2.x = addplane1.x + addplane1.width + 70;
					addplane2.y = addplane1.y;
					addplane2.setMaskOnField(0);
					
					addplane3.reScale(700);//Улица
					addplane3.x = testplane.x;
					addplane3.y = addplane2.y+addplane2.height+20;
					addplane3.setMaskOnField(0);
					
					addplane4.reScale(180);//Дом
					addplane4.x = addplane3.x + addplane3.width + 40;
					addplane4.y = addplane3.y;
					addplane4.setMaskOnField(0);
					
					addplane5.reScale(180);//Корпус
					addplane5.x = addplane4.x + addplane4.width + 40;
					addplane5.y = addplane4.y;
					addplane5.setMaskOnField(0);
					
					addplane6.reScale(180);//Квартира
					addplane6.x = addplane5.x + addplane5.width + 40;
					addplane6.y = addplane5.y;
					addplane6.setMaskOnField(0);

					
					up_txt.defaultTextFormat = micro_fmt;
					up_txt.embedFonts = true;
					up_txt.x = testplane.x;
					up_txt.y = testplane.y - 25;
					up_txt.width = 850;
					up_txt_str = "Фамилия                                                   Имя (инициал)   Отчество (инициал) ";
					down_txt.visible = false;
					
					txt1.visible = true;
					txt1.defaultTextFormat = micro_fmt;
					txt1.x = up_txt.x;
					txt1.width = 1000;
					txt1.y = addplane4.y - 25;
					txt1_str = "Улица                                                                                      Дом                     Корпус                  Квартира";
					
					fields_count = 7;
					
					if (TmpModel.payment.getExtraDataIDByName("payer_io") == -1)
					{
						TmpModel.payment.addExtraDataField("payer_io", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address1") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address1", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address2") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address2", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address3") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address3", "");
					}
					if (TmpModel.payment.getExtraDataIDByName("_field_address4") == -1)
					{
						TmpModel.payment.addExtraDataField("_field_address4", "");
					}
					
					addplane1.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("payer_io"));
					addplane2.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address"));
					addplane3.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address1"));
					addplane4.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address2"));
					addplane5.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address3"));
					addplane6.text = TmpModel.payment.getExtraDataByID(TmpModel.payment.getExtraDataIDByName("_field_address4"));
					keyboard.nullRestrickt();
					addplane5.swReady = true;
					addplane6.swReady = true;
					if (current_indx == 1)
					{
						setLimits(25, 25, 1);
					}
					else if (current_indx == 2)
					{
						setLimits(1, 1, 1);
					}
					else if (current_indx == 3)
					{
						setLimits(1, 1, 1);
					}
					else if (current_indx == 4)
					{
						setLimits(50, 50, 1);
					}
					else if (current_indx == 5)
					{
						setLimits(4, 4, 1);
					}else if (current_indx == 6)
					{
						setLimits(4, 4, 0);
					}else if (current_indx == 7)
					{
						setLimits(4, 4, 0);
					}
				}
			}
			testplane.text = ph;
			up_txt.text = up_txt_str;
			down_txt.text = down_txt_str;
			txt1.text = txt1_str;
		}
		
		private function setLimits(num_limit:Number,max:Number,min:Number=0):void {
			keyboard.num_limit = num_limit;
			keypad.num_limit = num_limit;
			acc_number_length = max;//max количество символов в поле ввода
			acc_number_min_length = min;//min количество символов
		}
		
		private var nic_value:String = "NIC-D";
		
		private function validateRegularExpression(phonePattern:RegExp, accauntnumber:String):Boolean
		{
			return accauntnumber.search(phonePattern) == 0;
			
			var result:Object = phonePattern.exec(accauntnumber);
			if (result == null)
			{
				return false;
			}
			return true;
		}
		
		private function loadPictures():void
		{
			prv_logo = new ButtonProvider("prov");
			prv_logo.x = 50;
			prv_logo.y = 250;
			addChild(prv_logo);
		}
		
		private function allPicLoaded(e:Event):void
		{
			pic_count--;
			if (pic_count == 0)
			{
				
				btn_next.x = stage.stageWidth - (btn_next.width + 20)
				btn_next.y = stage.stageHeight - (btn_next.height + 20);
				
				keypad.x = btn_next.x - 90;
				keypad.y = 250;
				
				btn_nic_d.y = 530;
				btn_nic_d.x = 500;
				btn_nic_d.addTextIcon("NIC-D", 22, 15, 20);
				btn_nic_d.btn_index = 0;
				btn_nic_d.visible = false;
				
				btn_nic_r.y = btn_nic_d.y;
				btn_nic_r.x = btn_nic_d.x + btn_nic_d.width + 15;
				btn_nic_r.addTextIcon("NIC-REG", 22, 10, 20);
				btn_nic_r.btn_index = 1;
				btn_nic_r.visible = false;
			}
		}
		
		private function pressBtn(e:Event):void
		{
			switch (e.target.name)
			{
				case "next": 
					prepareDataToConfirm();//TODO: разобрать
					TmpModel.payment.validateAccount( TmpModel.payment.accauntnumber);
					TmpModel.tmpGlobalController.onClick("confirm_userdata");//TODO: как это мы переходим когда не известны результаты проверки.
					break;
				case "nic_ru": 
					nic_value = ((e.target as ButtonBase).btn_index == 0) ? "NIC-D" : "NIC-REG";
					reDraw2();
					break;
			}
		}
	}
}